<template>
  <div class="article-list">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="别划拉了，没有啦🤑🤑🤑"
      :error.sync="isErr"
      error-text="出错了，点我永生"
      @load="getArticleList"
    >
      <van-swipe-cell
        :disabled="disableSwiper"
        v-for="item in articleList"
        :key="item.id"
      >
        <van-cell center :to="`/show?id=${item.id}`">
          <h3 slot="title" class="list-title text">{{ item.title }}</h3>
          <div slot="label" class="list-desc">
            <p class="text">
              {{ item.description }}
            </p>
            <p class="desc">
              <span><van-icon name="eye" />收藏({{ item.lovenum }})</span>
              <span><van-icon name="good-job" />点赞({{ item.click }})</span>
            </p>
          </div>
          <img
            class="list-img"
            :src="`http://124.223.14.236:8060/${item.pic}`"
            alt=""
          />
        </van-cell>
        <template #right>
          <!-- <van-button square type="danger" text="取消" /> -->
          <slot></slot>
        </template>
      </van-swipe-cell>
    </van-list>
  </div>
</template>

<script>
import { getCateIdListApi } from "../api";
export default {
  name: "ArticleList",
  data() {
    return {
      articleList: [],
      loading: false,
      finished: false,
      page: 1,
      isErr: false,
    };
  },
  props: {
    // 是否禁止滑动
    disableSwiper: {
      type: Boolean,
      default: true,
    },
    cateid: [String,Number],
  },
  methods: {
    async getArticleList() {
      // console.log(cateid);
      try {
        const {
          data: {
            list: { count, data },
          },
        } = await getCateIdListApi({
          page: this.page,
          limit: 10,
          cateid: this.cateid,
        });
        // console.log(list);
        this.articleList.push(...data);
        // console.log(data);
        this.articleList.length >= count ? (this.finished = true) : this.page++;
      } catch (err) {
        this.isErr = true;
      } finally {
        this.loading = false;
      }
    },
  },
};
</script>
<style scoped lang="less">
.article-list {
  margin-top: 10px;
  .list-title {
    font-size: 32px;
    color: #222;
    font-weight: normal;
  }
  .list-desc {
    font-size: 28px;
    .desc {
      color: #aaa;
      font-size: 24px;
      span {
        margin-right: 20px;
      }
    }
  }
  /deep/ .van-swipe-cell__value {
    width: 260px;
    flex: unset;
  }
  .list-img {
    // width: 240px;
    height: 200px;
  }
  /deep/ .van-swipe-cell__right {
    .van-button {
      height: 100%;
    }
  }
}
.text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
}
</style>